<?php
namespace app\index\controller;

use think\Request;
use app\index\model\UserModel;

class Data extends BaseController
{
    public function get()
    {
        $playerId = request()->param('playerId');
        if(empty($playerId))
    	{
    		return 'error_player_id';
    	}
    	// load from db
        $user = UserModel::where('wx_pid',$playerId)->find();

    	return $this->out($user);
    }

    public function save()
    {
        $playerId = request()->param('playerId');
        $playerData = request()->param('playerData');

        if(empty($playerId))
    	{
    		return 'error_player_id';
    	}
    	if(empty($playerData))
    	{
    		return 'error_player_data';
    	}
        $res = UserModel::saveUserData($playerId, $playerData);
        if(empty($res))
        {
            return 'error_layer_save';
        }
    	return $this->out($res);
    }

    public function serverTime()
    {
        return $this->out(array());
    }

}
